package club.ruanx.movie.repository;

import club.ruanx.core.repository.base.BaseRepository;
import club.ruanx.movie.entity.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author 阮胜
 * @date 2018/10/22 14:50
 */
public interface PersonRepository extends BaseRepository<Person, String> {

    @Query(value = "SELECT * FROM t_movie_person WHERE JSON_CONTAINS(PROFESSIONS,JSON_ARRAY(:profession))", nativeQuery = true)
    Page<Person> findByProfession(@Param("profession") Integer profession, Pageable pageable);

    boolean existsBySpiderId(String spiderId);

    @Query("from Person as p where length(p.photos)>0")
    Page<Person> findAllWherePhotosNotEmpty(Pageable pageable);
}
